var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = cc._decorator,
    s = r.ccclass,
    l = r.property,
    _ = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.map_node = null),
                (t.left_mian_tower = null),
                (t.right_mian_tower = null),
                (t._width = 0),
                (t._height = 0),
                (t.player_node = null),
                (t.start_move = !1),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                (this._width = (1.5 * this.map_node.width) / 2 - 256),
                    (this._height = (1.5 * this.map_node.height) / 2 - 256);
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(n.default.SEND_PLAYER_POS_INFO, this.updateGameCamera, this),
                    this.attachEvent(n.default.SEND_GAME_OVER_INFO, this.showGameOver, this),
                    this.attachEvent(n.default.SEND_SHOW_GAME_MAP_INFO, this.showMapInfo, this);
            }),
            (t.prototype.showGameOver = function () {
                (this.start_move = !0), this.unscheduleAllCallbacks();
                var e = i.GlobalParams.MatchMyIndex % 2 == 0 ? this.left_mian_tower : this.right_mian_tower,
                    t = i.GlobalParams.MatchMyIndex % 2 == 0 ? this.right_mian_tower : this.left_mian_tower,
                    o = i.GlobalParams.GamePlayerWin ? t : e,
                    a = o.x,
                    n = o.y + 150,
                    r = this._width - cc.winSize.width / 2,
                    s = this._height - cc.winSize.height / 2;
                a < -r ? (a = -r) : a > r && (a = r),
                    n < -s ? (n = -s) : n > s && (n = s),
                    cc
                        .tween(this.node)
                        .to(i.GlobalParams.GameUpdateTime, { position: cc.v2(a, n) })
                        .start();
            }),
            (t.prototype.updateGameCamera = function (e, t) {
                (this.player_node = t), this.unscheduleAllCallbacks(), this.schedule(this.updateCamera);
            }),
            (t.prototype.updateCamera = function () {
                if (this.player_node && this.player_node.isValid && !this.start_move) {
                    var e = this.player_node.x,
                        t = this.player_node.y + 150,
                        o = this._width - cc.winSize.width / 2,
                        a = this._height - cc.winSize.height / 2;
                    e < -o ? (e = -o) : e > o && (e = o),
                        t < -a ? (t = -a) : t > a && (t = a),
                        this.node.setPosition(cc.v2(e, t));
                }
            }),
            (t.prototype.showMapInfo = function (e, t) {
                var o = this;
                this.start_move = !0;
                var a = t,
                    n = this.node.getPosition(),
                    i = a.x,
                    r = a.y + 150,
                    s = this._width - cc.winSize.width / 2,
                    l = this._height - cc.winSize.height / 2;
                i < -s ? (i = -s) : i > s && (i = s),
                    r < -l ? (r = -l) : r > l && (r = l),
                    cc
                        .tween(this.node)
                        .to(3, { position: cc.v2(i, r) })
                        .delay(0.8)
                        .to(1.2, { position: cc.v2(n.x, n.y) })
                        .call(function () {
                            o.start_move = !1;
                        })
                        .start();
            }),
            oo([l(cc.Node)], t.prototype, "map_node", void 0),
            oo([l(cc.Node)], t.prototype, "left_mian_tower", void 0),
            oo([l(cc.Node)], t.prototype, "right_mian_tower", void 0),
            oo([s], t)
        );
    })(a.default);
o.default = _;
